/**
 * Created by Administrator on 2018/4/26.
 */

// 表单的删除、及编辑弹出框

$(".js-del").click(function () {
    var href = $(this).data("href")
    swal({
            title: "确定删除吗？",
            // text: "你将无法恢复该条！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定！",
            closeOnConfirm: false
        },
        function () {
                $.ajax({
                url: href,
                success: function (res) {
                    swal(res.result, "", "success")
                    }
            })
        });

})

$(".js-edit").click(function () {
    var href = $(this).data("href")
    swal({
            title: "确定更新吗？",
            text: "你将更新数据！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定！",
            closeOnConfirm: false
        },
        function () {
            swal("成功！", "修改用户成功！", "success");
            window.location.href = href
        });
})

// 表单验证
$(document).ready(function() {
    /**
     * 下面是进行插件初始化
     * 你只需传入相应的键值对
     * */
    $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {/*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {/*验证*/
                username: {/*键名username和input name值对应*/
                    message: 'The username is not valid',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '用户名不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 3,
                            max: 30,
                            message: '用户名长度必须在6到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                password: {
                    message:'密码无效',
                    validators: {
                        notEmpty: {
                            message: '密码不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: '用户名长度必须在6到30之间'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: '邮箱地址不能为空'
                        },
                        emailAddress: {
                            message: '邮箱地址格式不对'
                        }
                    }
                },
                'status': {
                    validators: {
                        notEmpty: {
                            message: '添加新用户状态必须为激活'
                        }
                    }
                }

            }
        });

});